import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Game {
    public static final String [] SUITS = {"♥","♠","♦","♣"};

    public List<Card> creatCard(){
        List<Card> CardsBox = new ArrayList<>();

        for (int i = 0; i < SUITS.length; i++) {
            for (int j = 1; j <= 13; j++) {
//                String suit = SUITS[i];
//                int rank = j;
                Card card = new Card(SUITS[i],j);
                CardsBox.add(card);
            }
        }
        return CardsBox;
    }

    public void shuffle(List<Card> CardList){
        Random random = new Random();
        for (int i = CardList.size() - 1; i > 0 ; i--) {
            int randIndex = random.nextInt(i);
            swap(CardList,i,randIndex);
        }
    }

    private void swap(List<Card> CardList,int i ,int j){
//        Card tmp = CardList[i];
//        CardList[i] = CardList[j];
//        CardList[j] = tmp;

        Card tmp = CardList.get(i);
        CardList.set(i,CardList.get(j));
        CardList.set(j,tmp);
    }

    public List<List<Card>> play(List<Card> CardList){
        List<List<Card>> hand = new ArrayList<>();

        List<Card> hand0 = new ArrayList<>();
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();

        hand.add(hand0);
        hand.add(hand1);
        hand.add(hand2);

        //三个人轮流抽牌,一次一张,共抽5个回合
        for (int i = 0; i < 5; i++) {

            for (int j = 0; j < 3; j++) {
                Card card = CardList.remove(0);
                hand.get(j).add(card);
            }
        }
        return hand;
    }


}
